import request from "@/utils/request";
import type { AxiosPromise } from "axios";
import type { SysAnnouncementForm, SysAnnouncementQuery, SysAnnouncementVo } from "@/api/system/announcement/types";

/**
 * 查询系统通告表
 * @param query
 * @returns {*}
 */
export const listAnnouncement = (query?: SysAnnouncementQuery): AxiosPromise<SysAnnouncementVo[]> => {
  return request({
    url: "/system/sysAnnouncement/list",
    method: "get",
    params: query
  });
};

/**
 * 新增系统通告
 * @param data
 */
export const addAnnouncement = (data: SysAnnouncementForm) => {
  return request({
    url: "/system/sysAnnouncement",
    method: "post",
    data: data
  });
};

/**
 * 删除系统通告
 * @param id
 */
export const delAnnouncement = (id: string | number | Array<string | number>) => {
  return request({
    url: "/system/sysAnnouncement/" + id,
    method: "delete"
  });
};

/**
 * 修改系统通告
 * @param data
 */
export const updateAnnouncement = (data: SysAnnouncementForm) => {
  return request({
    url: "/system/sysAnnouncement",
    method: "put",
    data: data
  });
};

/**
 * 查询系统通告详情
 * @param id
 */
export const getAnnouncement = (id: string | number): AxiosPromise<SysAnnouncementVo> => {
  return request({
    url: "/system/sysAnnouncement/" + id,
    method: "get"
  });
};

/**
 * 发布系统通告
 */
export const publishAnnouncement = (id: string | number) => {
  return request({
    url: `/system/sysAnnouncement/publish/${id}`,
    method: "post"
  });
};

/**
 * 撤销系统通告
 */
export const quashAnnouncement = (id: string | number) => {
  return request({
    url: `/system/sysAnnouncement/quash/${id}`,
    method: "post"
  });
};

/**
 * 查询未读消息数量
 */
export const getUnreadMessageCount = () => {
  return request({
    url: `/system/sysAnnouncement/getUnreadMessageCount`,
    method: "get"
  });
};

/**
 * 查询未读消息
 */
export const getUnreadMessageByUserId = () => {
  return request({
    url: `/system/sysAnnouncement/getUnreadMessageByUserId`,
    method: "get"
  });
};
